import { Component, OnInit } from '@angular/core';
import { JsonApiService } from "app/core/api/json-api.service"; //http请求配置引入
import { Router, ActivatedRoute } from "@angular/router"; //路由引入
import { config } from '../../shared/smartadmin.config';

declare var $: any;
declare var Viewer: any;
@Component({
	selector: 'sa-device-installation',
	templateUrl: './device-installation.component.html',
	styleUrls: ['./device-installation.css']
})
export class DeviceInstallationComponent implements OnInit {
	tableData: any[] = []; //table数据
	totalCount: number = 0; //分页总条数
	curPage: number = 1; //分页当前页
	pageSize: number = 10; //内置的分页每页条数
	tableParam: any = {
		searchKey: '',
		carType: '',
		selectedCompanyId: '',
		selectedCompanyName: '',
		deviceId: '',
		carNumber: '',
		userName: '',
		userId: '',
		auditStatus: '',
		sensorHullName: '',
		startTime: '',
		endTime: ''
	}
	userList:any; //用户数据
	inputCompanyTreeCarData:any = {};//车辆运行状态模块跳转该页面传递过来的参数
	isViewer: boolean = false; //默认隐藏
	isShowDelete = true; // 默认不显示删除按钮
	constructor(private jsonApiService: JsonApiService, private router: Router, private activatedRoute: ActivatedRoute) {
		activatedRoute.queryParams.subscribe(queryParams => {
			this.curPage = queryParams.nowPage || 1;
		});
	}
	ngOnInit() {
		this.initAllUser().then(()=>{
			this.selectUserName();
			this.load();
		});
		this.initBtn();
		this.initDate();
	}
	//初始化权限按钮
	initBtn() {
		// 公司的删除按钮的权限
		// var btnData = JSON.parse(decodeURIComponent(localStorage.getItem('cargpsw_wx:bind:adviseLog')));
		// if(!btnData) {
		// 	return
		// };
		// for(let item of btnData) {
		// 	if(item.sourceKey === "wx-bind:advise-log:deleteBtn" && item.parentId) {
		// 		this.isShowDelete = true;
		// 	}
		// }
	}
	//table刷新
	refresh() {
		this.load();
	}
	//表格搜索
	tableSearch() {
		this.curPage = 1;
		this.load();
	}
	//分页回调
	paginate(e) {
		this.curPage = e.page + 1;
		this.pageSize = e.rows;
		this.load();
	}
	//公司选中回调
	companySelected(data){
		this.tableParam.selectedCompanyId = data.companyId;
		this.tableParam.selectedCompanyName = data.companyName;
		this.tableParam.deviceId = data.deviceId;
		this.tableParam.carNumber = data.carNumber;
	}
	//擦除用户所选值
	delUserName(){
		this.tableParam.userName = '';
		this.tableParam.userId = '';
		//采用简单粗暴的方法清除;官方推荐的方法失效
		var str=$("<span class='select2-selection__placeholder'>请选择</span>");
		$('#userNameSelect2').val("");
		$("#select2-userNameSelect2-container").empty();
		$("#select2-userNameSelect2-container").attr("title","");
		$("#select2-userNameSelect2-container").prepend(str);
		this.load();
	}
	//初始化select2 选项
	selectUserName(){
		var that = this;
		System.import('script-loader!select2/dist/js/select2.min.js').then(()=>{
			System.import('assets/js/select2-zh-CN.js').then(()=>{
				$("#userNameSelect2").select2({
			    	language : "zh-CN",
			    	placeholder :"请选择",
			    	allowClear : true,
			    	data : this.userList,//为Select添加数据
			        templateResult: this.formatRepo
			    }).on ("select2:select", function (e){
		        	  	var data = e.params.data;
		        	  	that.tableParam.userName = data.text;
		        	  	that.tableParam.userId = data.id;
		        });
			})
		})
	}
	//select2 格式回调函数
	formatRepo (state) {
		if (!state.id) {return state.text};
		var $state = $('<span><i class="fa fa-user green"></i>&nbsp;&nbsp;' + state.text + '</span>');
		return $state;
	}
	//拉取
	initAllUser(){
		var that = this;
		return new Promise(function (resolve, reject) {
			that.jsonApiService.http("user/getAllUserList.html",null).subscribe(data=> {
				if(data.success){
					var userList = data.data;
		        	var selectdata = [];
		        	for(var i = 0 ; i < userList.length ; i++) {
		        		var obj = {
		        			id:userList[i].id,
		        			text:userList[i].name,
		        		}
		        		selectdata[i] = obj;
		        	}
				}
				that.userList = selectdata;
				resolve();
			})
		})
	}
	initDate(){
		var that = this;
		return new Promise(function (resolve, reject) {
			System.import('assets/js/datepicker/js/bootstrap-datetimepicker.min.js').then(()=>{
					System.import('assets/js/datepicker/locales/bootstrap-datetimepicker.zh-CN.js').then(()=>{
						$("#datetimepicker1").datetimepicker({//时间插件
							format: "yyyy-mm-dd hh:ii:ss",
						    language: "zh-CN",
						    autoclose: true,
						}).on("changeDate", function(e){
							var date = e.date;
							var time = common.getTimeMmss(date);
							$("#datetimepicker2").datetimepicker("setStartDate", time);
							that.tableParam.startTime=time;
						});
						$("#datetimepicker2").datetimepicker({//时间插件
							format: "yyyy-mm-dd hh:ii:ss",
						    language: "zh-CN",
						    autoclose: true,
						}).on("changeDate", function(e){
							var date = e.date;
							var time = common.getTimeMmss(date);
							$("#datetimepicker1").datetimepicker("setEndDate", time);
							that.tableParam.endTime=time;
						});

						resolve();
					});
				}
			);
		})

	}
	//清除所选时间
	del_date(){
		this.tableParam.startTime='';
		this.tableParam.endTime='';
		$("#datetimepicker1").val('').change();
		$("#datetimepicker2").val('').change();
		$("#datetimepicker2").datetimepicker("setStartDate", null);
		$("#datetimepicker1").datetimepicker("setEndDate", null);
	}
	// 删除传感器外壳编码
	delSensorHullName() {
		this.tableParam.sensorHullName = '';
	}
	//初始化加载list数据
	load() {
		this.tableParam.startTime =$('#datetimepicker1').val();
		this.tableParam.endTime=$('#datetimepicker2').val();
		if(this.tableParam.startTime==''&&this.tableParam.endTime!==''){
			this.jsonApiService.message('起始时间不能为空');
			return;
		}
		if(this.tableParam.startTime!==''&&this.tableParam.endTime==''){
			this.jsonApiService.message('结束时间不能为空')
			return;
		}
		if(this.tableParam.startTime!==''&& !common.checkDateFormat(this.tableParam.startTime)){
			this.jsonApiService.message('起始时间格式错误')
			return;
		}
		if(this.tableParam.endTime!==''&& !common.checkDateFormat(this.tableParam.endTime)){
			this.jsonApiService.message('结束时间格式错误')
			return;
		}

		let data = {
			pageSize: this.pageSize,
			nowPage: this.curPage,
			parameters: {
				searchKey: common.stringTrim(this.tableParam.searchKey),
				useTypeL2: this.tableParam.carType,
				deviceId: this.tableParam.deviceId,
				carNumber: this.tableParam.carNumber,
				companyId: this.tableParam.selectedCompanyId,
				companyName: this.tableParam.selectedCompanyName,
				createForUser: this.tableParam.userName,
				userId: this.tableParam.userId,
				startTime: this.tableParam.startTime,
				endTime: this.tableParam.endTime,
				auditStatus: this.tableParam.auditStatus,
				sensorHullName: this.tableParam.sensorHullName
			}
		}
		let reqdata = 'gridPager=' + JSON.stringify(data);
		this.jsonApiService.http("deviceInstallRecord/list.html", reqdata).subscribe(result => {
			if (result.isSuccess && result.exhibitDatas) {
				for(var i=0;i< result.exhibitDatas.length;i++){
					if(result.exhibitDatas[i].useTypeL2 == '0211'){
						result.exhibitDatas[i].useTypeName = '后挂双桶'
					}else if(result.exhibitDatas[i].useTypeL2 == '0214'){
						result.exhibitDatas[i].useTypeName = '侧挂拉杆'
					}else if(result.exhibitDatas[i].useTypeL2 == '0213'){
						result.exhibitDatas[i].useTypeName = '侧挂链条'
					}

					result.exhibitDatas[i].duration = common.secondToDate(result.exhibitDatas[i].duration)

				}
				this.tableData = result.exhibitDatas
				this.totalCount = result.recordCount;
			}
		});
	}
	// 数据导出
	exportData(){
		this.tableParam.startTime =$('#datetimepicker1').val();
		this.tableParam.endTime=$('#datetimepicker2').val();
		// if(this.tableParam.startTime==''&&this.tableParam.endTime!==''){
		// 	this.jsonApiService.message('起始时间不能为空');
		// 	return;
		// }
		// if(this.tableParam.startTime!==''&&this.tableParam.endTime==''){
		// 	this.jsonApiService.message('结束时间不能为空')
		// 	return;
		// }
		// if(this.tableParam.startTime!==''&& !common.checkDateFormat(this.tableParam.startTime)){
		// 	this.jsonApiService.message('起始时间格式错误')
		// 	return;
		// }
		// if(this.tableParam.endTime!==''&& !common.checkDateFormat(this.tableParam.endTime)){
		// 	this.jsonApiService.message('结束时间格式错误')
		// 	return;
		// }
        let data = {
			pageSize: this.pageSize,
			nowPage: this.curPage,
			parameters: {
				searchKey: common.stringTrim(this.tableParam.searchKey),
				useTypeL2: this.tableParam.carType,
				deviceId: this.tableParam.deviceId,
				carNumber: this.tableParam.carNumber,
				companyId: this.tableParam.selectedCompanyId,
				companyName: this.tableParam.selectedCompanyName,
				createForUser: this.tableParam.userName,
				userId: this.tableParam.userId,
				startTime: this.tableParam.startTime,
				endTime: this.tableParam.endTime,
				type: '1', //type1 导出
				auditStatus: this.tableParam.auditStatus
			}
		}
		let timeCheck = common.correctTime(data.parameters, ['type'])
		if(!timeCheck.status){
			this.jsonApiService.message(timeCheck.message);
			return;
		}
		common.exprotDataFile(data, 'gridPager', config.BaseURL + 'deviceInstallRecord/list.html')
	}
	// 删除登录日志
	deleteRow(row) {
		this.jsonApiService.confirm_message("此操作将永久删除数据,确认要删除?").then(() => {
			let parameters = {
				id: row.id,
			}
			this.jsonApiService.http_obj("deviceInstallRecord/deletedById.html", parameters).subscribe(data => {
				this.jsonApiService.message(data.message);
				this.tableParam.carType = ''
				this.load();
			})
		})
	}

	/*
		设备安装审核
	*/
	auditStatus: any = '';
	auditOpinion: any = '';
	//审核状态改变
	auditStatusChange(val){
		this.auditStatus = val;
	}
	//打开
	auditOpen(row,modal){
		this.rowId = row.id;
		this.auditOpinion = row.auditOpinion;
		if(row.auditStatus == 1){
			this.auditStatus = '1'
		}else if(row.auditStatus == 2){
			this.auditStatus = '2'
		}else{
			this.auditStatus = ''
		}
		modal.show()
	}
	//关闭
	cancelAudit(modal){
		this.rowId = '';
		this.auditOpinion = '';
		this.auditStatus = '';
		modal.hide();
	}
	//确定
	auditSubmit(modal){
		if(this.auditStatus == ''){
			this.jsonApiService.message("请先选择审核状态");
			return
		}

		if(this.auditStatus == '1' && this.auditOpinion == ''){
			this.auditOpinion = '合格'
		}

		if(this.auditStatus == '2' && this.auditOpinion == ''){
			this.jsonApiService.message("请输入审核不通过原因");
			return
		}

		let reqdata = "id="+this.rowId+"&auditStatus="+this.auditStatus + "&auditOpinion=" + this.auditOpinion;
		this.jsonApiService.http("deviceInstallRecord/auditById.html", reqdata).subscribe(data => {
			this.jsonApiService.message(data.message);
			this.load();
			modal.hide();
		})
	}




	/**
	 * 设备安装记录
	 * 详情以及编辑
	 */

	carDataListShow: any=[];
	rowId :any = '';
	rowUseTypeL2: any = ''
	lisLen: any = '';
	detailsTitleList: any = []
	// 添加公司弹框
	showDetails(row,modal,type) {
		var self = this;
		self.carDataListShow = [];
		self.rowId = row.id;
		self.rowUseTypeL2 = row.useTypeL2;
		self.rowCarNumber = row.carNumber;
		self.detailsTitleList = [];
		$('#myTab .s-lis').removeClass('active')
		$('.tab-content .tab-pane').removeClass('active')
		// self.detailsTitle(row); //请求头部
		//请求详情头部
		let reqdata = "id="+row.id;
		self.jsonApiService.http("deviceInstallRecord/getTabTitle.html", reqdata).subscribe(data => {
			if(data.success){
				self.detailsTitleList = data.data;
				self.lisLen = data.data.length
				//请求表头
				if(type == '1'){
					$('#OriginalLi').addClass('active')
					$('#Original').addClass('active')
					// self.getTabData('1','') //原车信息

					if(row.deviceMeasureEntity == null){
						self.detailsMain_Original.measureInfoList = []
					}else{
						self.detailsMain_Original = row.deviceMeasureEntity;
					}

					if(row.sensorChannel){
						var sensorChannel = row.sensorChannel.split(',');
						self.detailsMain_Original.sensorChannel = sensorChannel;
					}else{
						self.detailsMain_Original.sensorChannel = [];
					}
					self.detailsMain_Original.useTypeL2 = row.useTypeL2;
				}else if(type == '2'){

					$('#InstallationRecordLi').addClass('active')
					$('#InstallationRecord').addClass('active')
					self.getTabData('InstallationRecord','3','') //安装记录
				}

				if(self.isViewer && $(".viewer-container").length >0){
					self.viewer.destroy();
				}

				modal.show();
			}
		})

	}
	// 关闭
	itemModalClose(modal) {
		this.installRecordDetail ={
			operator: '',
			startTime: '',
			endTime: '',
			address: '',
			detail: [],
			id: ''
		}
		this.isShowInstall = true;
		modal.hide();
	}

	detailsMain_Original: any = {
		useTypeL2: '',
		measureInfoList: [],
		sensorChannel: [],
		sm: '',
		hwVersion: '',
		version: ''
	}; //原车信息
	detailsMain_host: any = {
		deviceInstallInfo: []
	}; //主机接线
	detailsMain_beam: any = {
		deviceInstallInfo: []
	}; //横梁焊接
	detailsMain_verticalBeam: any = {
		deviceInstallInfo: []
	}; //竖梁焊接
	detailsMain_ironPlate: any = {
		deviceInstallInfo: []
	}; //铁板焊接
	detailsMain_sensor: any = {
		deviceInstallInfo: []
	}; //传感器
	detailsMain_chain: any = {
		deviceInstallInfo: []
	}; //链条走线
	detailsMain_switch: any = {
		deviceInstallInfo: []
	}; //接近开关
	detailsMain_monitor: any = {
		deviceInstallInfo: []
	}; //显示器
	detailsMain_cardReader: any = {
		deviceInstallInfo: []
	}; //读卡器
	detailsMain_Routing: any = {
		deviceInstallInfo: []
	}; //走线
	detailsMain_BrokenLine: any = {
		deviceInstallInfo: []
	}; //破线
	detailsMain_InstallationRecord: any = {
		install: {},
		info: []
	}; //安装记录
	getTabData(name,type,id){
		var ids;
		$('#installRecordStartTime').css('display','none')
		$('#installRecordEndTime').css('display','none')
		if(type == '1' || type == '3'){
			// $('#myTab .s-lis').removeClass('active')
			// $('.tab-content .tab-pane').removeClass('active')
			ids = this.rowId;
			// if(type == '1'){
			// 	$('#OriginalLi').addClass('active')
			// 	$('#Original').addClass('active')
			// }else{
			// 	$('#InstallationRecordLi').addClass('active')
			// 	$('#InstallationRecord').addClass('active')
			// }
		}else{
			ids = id;
		}
		let reqdata = "id="+ids + "&type=" + type;
		this.jsonApiService.http("deviceInstallRecord/getTabData.html", reqdata).subscribe(data => {
			if(data.success){
				if(type == '2'){
					if(name.indexOf('host') !=-1){
						this.detailsMain_host = data.data;
					}else if(name.indexOf('beam') !=-1){
						this.detailsMain_beam = data.data;
					}else if(name.indexOf('verticalBeam') !=-1){
						this.detailsMain_verticalBeam = data.data;
					}else if(name.indexOf('ironPlate') !=-1){
						this.detailsMain_ironPlate = data.data;
					}else if(name.indexOf('sensor') !=-1){
						this.detailsMain_sensor = data.data;
					}else if(name.indexOf('chain') !=-1){
						this.detailsMain_chain = data.data;
					}else if(name.indexOf('switch') !=-1){
						this.detailsMain_switch = data.data;
					}else if(name.indexOf('monitor') !=-1){
						this.detailsMain_monitor = data.data;
					}else if(name.indexOf('cardReader') !=-1){
						this.detailsMain_cardReader = data.data;
					}else if(name.indexOf('Routing') !=-1){
						this.detailsMain_Routing = data.data;
					}else if(name.indexOf('BrokenLine') !=-1){
						this.detailsMain_BrokenLine = data.data;
					}

				}else if(type == '3'){
					this.detailsMain_InstallationRecord = data.data;
					this.installRecordDetail.operator = data.data.install.operator;
					this.installRecordDetail.startTime = data.data.install.startTime;
					this.installRecordDetail.endTime = data.data.install.endTime;
					this.installRecordDetail.address = data.data.install.address;
					this.installRecordDetail.id = data.data.install.id;
					for(var i=0;i< data.data.info.length;i++){
						var infoObj={
							id: data.data.info[i].id,
							operator: data.data.info[i].operator,
						}
						this.installRecordDetail.detail.push(infoObj)
					}
				}
			}
		})
	}

	//初始化日期
	initInstallDate(){
		var that = this;
		System.import('assets/js/datepicker/js/bootstrap-datetimepicker.min.js').then(
			()=>{System.import('assets/js/datepicker/locales/bootstrap-datetimepicker.zh-CN.js').then(()=>{
				$("#installRecordStartTime").datetimepicker({//时间插件
					format: "yyyy-mm-dd hh:ii:ss",
					language: "zh-CN",
					autoclose: true,
				}).on("changeDate", function(e){
					var date = e.date;
					if(!date){return;}
					var time = common.getTimeMmss(date);
					$("#installRecordStartTime").val(time);
					that.installRecordDetail.startTime=time;
				});
				$("#installRecordEndTime").datetimepicker({//时间插件
					format: "yyyy-mm-dd hh:ii:ss",
					language: "zh-CN",
					autoclose: true,
				}).on("changeDate", function(e){
					var date = e.date;
					if(!date){return;}
					var time = common.getTimeMmss(date);
					that.installRecordDetail.endTime=time;
					$("#installRecordEndTime").val(time);
					// $("#installRecordEndTime").datetimepicker("setEndDate", time);
				});
			});
		});
	}
	//是否显示安装记录编辑
	isShowInstall: any = true; //默认不编辑
	installRecordDetail: any={
		operator: '',
		startTime: '',
		endTime: '',
		address: '',
		detail: [],
		id: ''
	}
	modifyInstall(type){
		this.isShowInstall = type;
		if(!type){
			$('#installRecordStartTime').css('display','block')
			$('#installRecordEndTime').css('display','block')
			this.initInstallDate()
		}else{
			this.installRecordDetail.detail = [];
			this.installRecordDetail.startTime = this.detailsMain_InstallationRecord.install.startTime;
			this.installRecordDetail.endTime = this.detailsMain_InstallationRecord.install.endTime;
			this.installRecordDetail.operator =this.detailsMain_InstallationRecord.install.operator;
			this.installRecordDetail.startTime = this.detailsMain_InstallationRecord.install.startTime;
			this.installRecordDetail.endTime = this.detailsMain_InstallationRecord.install.endTime;
			this.installRecordDetail.address = this.detailsMain_InstallationRecord.install.address;
			for(var i=0;i< this.detailsMain_InstallationRecord.info.length;i++){
				var infoObj={
					id: this.detailsMain_InstallationRecord.info[i].id,
					operator: this.detailsMain_InstallationRecord.info[i].operator,
				}
				this.installRecordDetail.detail.push(infoObj)
			}
			$('#installRecordStartTime').css('display','none')
			$('#installRecordEndTime').css('display','none')
		}
	}
	installSubmit(modal){
		var obj = this.installRecordDetail;
		obj.detail = JSON.stringify(obj.detail)
		this.jsonApiService.http_obj("deviceInstallRecord/updateDeatail.html",obj).subscribe(data=> {
			this.jsonApiService.message(data.message);
			if(data.success){
				this.load();
				this.itemModalClose(modal);
			}
		})
//		}
	}

	modalTit: any = '';
	lookImgList: any = {
		'deviceInstallInfo':[]
	}
	//查看图片
	lookImg(type,modal1,name,modal2){
		this.modalTit = name;
		var deviceInstallInfoList = [];
		let deviceInstallImage = [];
		if(type == 'Original'){
			var deviceInstallImageObj1,deviceInstallImageObj2;
			if(this.rowUseTypeL2 == '0211'){
				let obj1 = {
					"imageUrl": this.detailsMain_Original.carNumberUrl,
					"index":1,
					"name":"车牌号",
					"prefix":"",
					"value":""
				};
				deviceInstallImage.push(obj1)
				for(let j=0;j<this.detailsMain_Original.carDrivingLicenseUrl.length;j++){
					let obj2 = {
						"imageUrl": this.detailsMain_Original.carDrivingLicenseUrl[j],
						"index":3,
						"name":"行驶证/铭牌",
						"prefix":"",
						"value":""
					};
					deviceInstallImage.push(obj2)
				}
				for(let k=0;k<this.detailsMain_Original.carTailShelfUrl.length;k++){
					let obj3 = {
						"imageUrl": this.detailsMain_Original.carTailShelfUrl[k],
						"index":4,
						"name":"举伸架",
						"prefix":"",
						"value":""
					};
					deviceInstallImage.push(obj3)
				}

				deviceInstallImageObj1={
					"deviceInstallImage":[],
					"index":1,
					"isShow":1,
					"name":"车辆信息"
				}
				deviceInstallImageObj1.deviceInstallImage = deviceInstallImage;
				deviceInstallInfoList.push(deviceInstallImageObj1);
				// deviceInstallImageObj2={
				// 	"deviceInstallImage":this.detailsMain_Original.measureInfoList,
				// 	"index":1,
				// 	"isShow":1,
				// 	"name":"后挂信息"
				// }
				// deviceInstallInfoList.push(deviceInstallImageObj2);
			}else if(this.rowUseTypeL2 == '0213'){
				let obj1 = {
					"imageUrl": this.detailsMain_Original.carNumberUrl,
					"index":1,
					"name":"车牌号",
					"prefix":"",
					"value":""
				};
				deviceInstallImage.push(obj1)

				for(let j=0;j<this.detailsMain_Original.carDrivingLicenseUrl.length;j++){
					let obj2 = {
						"imageUrl": this.detailsMain_Original.carDrivingLicenseUrl[j],
						"index":3,
						"name":"行驶证/铭牌",
						"prefix":"",
						"value":""
					};
					deviceInstallImage.push(obj2)
				}
				for(let k=0;k<this.detailsMain_Original.carTailShelfUrl.length;k++){
					let obj3 = {
						"imageUrl": this.detailsMain_Original.carTailShelfUrl[k],
						"index":4,
						"name":"举伸架",
						"prefix":"",
						"value":""
					};
					deviceInstallImage.push(obj3)
				}
				deviceInstallImageObj1={
					"deviceInstallImage":[],
					"index":1,
					"isShow":1,
					"name":"车辆信息"
				}
				deviceInstallImageObj1.deviceInstallImage = deviceInstallImage;
				deviceInstallInfoList.push(deviceInstallImageObj1);
				// deviceInstallImageObj2={
				// 	"deviceInstallImage":this.detailsMain_Original.measureInfoList,
				// 	"index":1,
				// 	"isShow":1,
				// 	"name":"后挂信息"
				// }
				// deviceInstallInfoList.push(deviceInstallImageObj2);
			}else{
				let obj1 = {
					"imageUrl": this.detailsMain_Original.carNumberUrl,
					"index":1,
					"name":"车牌号",
					"prefix":"",
					"value":""
				};
				deviceInstallImage.push(obj1)
				for(let j=0;j<this.detailsMain_Original.carDrivingLicenseUrl.length;j++){
					let obj2 = {
						"imageUrl": this.detailsMain_Original.carDrivingLicenseUrl[j],
						"index":3,
						"name":"行驶证/铭牌",
						"prefix":"",
						"value":""
					};
					deviceInstallImage.push(obj2)
				}
				for(let k=0;k<this.detailsMain_Original.carTailShelfUrl.length;k++){
					let obj3 = {
						"imageUrl": this.detailsMain_Original.carTailShelfUrl[k],
						"index":4,
						"name":"举伸架",
						"prefix":"",
						"value":""
					};
					deviceInstallImage.push(obj3)
				}
				deviceInstallImageObj1={
					"deviceInstallImage":[],
					"index":1,
					"isShow":1,
					"name":"车辆信息"
				}
				deviceInstallImageObj1.deviceInstallImage = deviceInstallImage;
				deviceInstallInfoList.push(deviceInstallImageObj1);
				// deviceInstallImageObj2={
				// 	"deviceInstallImage":this.detailsMain_Original.measureInfoList,
				// 	"index":1,
				// 	"isShow":1,
				// 	"name":"后挂信息"
				// }
				// deviceInstallInfoList.push(deviceInstallImageObj2);
			}
			this.lookImgList.title = '原车信息'
			this.lookImgList.deviceInstallInfo = deviceInstallInfoList;
		}else if(type == 'host'){
			this.lookImgList = this.detailsMain_host;
		}else if(type == 'beam'){
			this.lookImgList = this.detailsMain_beam;
		}else if(type == 'verticalBeam'){
			this.lookImgList = this.detailsMain_verticalBeam;
		}else if(type == 'ironPlate'){
			this.lookImgList = this.detailsMain_ironPlate;
		}else if(type == 'sensor'){
			this.lookImgList = this.detailsMain_sensor;
		}else if(type == 'chain'){
			this.lookImgList = this.detailsMain_chain;
		}else if(type == 'switch'){
			this.lookImgList = this.detailsMain_switch;
		}else if(type == 'monitor'){
			this.lookImgList = this.detailsMain_monitor;
		}else if(type == 'cardReader'){
			this.lookImgList = this.detailsMain_cardReader;
		}else if(type == 'Routing'){
			this.lookImgList = this.detailsMain_Routing;
		}else if(type == 'BrokenLine'){
			this.lookImgList = this.detailsMain_BrokenLine;
		}

		if(this.isViewer && $(".viewer-container").length >0){
			this.viewer.destroy();
		}

		this.itemModalClose(modal2);
		modal1.show();
	}

	cancelLookImg(modal1,modal2){
		modal1.hide();
		modal2.show()
	}
	rowCarNumber: any = '';//示例图片展示车牌号码
	listImg: any = '';//上传图片
	showlistImg: any = '';//示例图片
	imgListLen: any = ''; //总共几张
	showlistIndex: any=''; //在第几张
	//查看示例图片
	showLookImgView(name,infoName,imageName,modal1,modal2,listImg){
		var imgList = $(".imgModalView img");
		this.imgListLen = imgList.length;
		for(var i=0;i< imgList.length;i++){
			if(imageName == imgList[i].alt){
				this.showlistIndex = i+1;
			}
		}
		let parameters = {
			name: name,
			infoName: infoName,
			imageName: imageName,
			useTypeL2: this.rowUseTypeL2,
		}
		this.jsonApiService.http_obj("deviceInstallRecord/figureDetail.html",parameters).subscribe(data=> {
			if(data.success){
				if(data.data.imageUrl){
					this.listImg = listImg;
					this.showlistImg = data.data.imageUrl;
					modal2.hide()
					modal1.show();
				}else{
					//如果暂无示例图片，则展开是图片本身
					this.listImg = listImg;
					this.showlistImg = '';
					modal2.hide()
					modal1.show();
					// this.jsonApiService.message('暂无示例图片');
				}

				if(this.isViewer && $(".viewer-container").length >0){
					$('.viewer-container').empty();
					$('.viewer-container').empty();
					this.viewer.destroy();
					this.isViewer = false;
				}
			}else{

				this.listImg = listImg;
				this.showlistImg = '';
				modal2.hide()
				modal1.show();
				// this.jsonApiService.message(data.message);
			}
		})
	}

	cancelShowLookImg(modal1,modal2){
		modal1.hide();
		modal2.show();
		if(this.isViewer && $(".viewer-container").length >0){
			$('.viewer-container').empty();
			this.viewer.destroy();
		}
	}
	//显示图片组件
	viewer: any='';


	bigImgClick(){
		// modal.show();
		if(this.isViewer && $(".viewer-container").length > 0){
			System.import('assets/js/viewer/viewer.js').then(
				()=>{System.import('assets/js/viewer/bootstrap.bundle.min.js').then(
					()=>{System.import('assets/js/viewer/viewer.css').then(()=>{
						this.showImg();
					})
				})
			})
		}else{
			this.showImg();
		}
	}
	showImg(){
		var that = this;
		var imgList
		imgList = $(".showImgContent")[0];
		this.viewer = new Viewer(imgList, {
			url: 'src',
			title: function (image) {
				return image.alt + ' (' + (this.index + 1) + '/' + this.length + ')' ;
			},
		});
		that.isViewer = true
	}
}